import { createRouter, createWebHistory } from 'vue-router'
import WeatherHome from '@/components/WeatherHome.vue'
import CityInfo from '@/components/CityInfo.vue'
import NotFoundView from '@/components/NotFoundView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      redirect: '/weather',
      component: WeatherHome,
    },
    {
      path: '/weather',
      name: 'weather',
      component: WeatherHome,
      children:[
        {path:':id?',name:'CityInfo', component:CityInfo},
      ]
    },
    {path:'/:pathMatch(.*)*',name:'notfound',component:NotFoundView},
  ],
})

router.beforeEach((to) => {
  if (to.path === '/weather') {
    return true
  }
})

export default router
